package au.com.cmcrc.tradelab.pm.environment;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import org.apache.log4j.Logger;


/**
 * @author Fawad Nazir (fawad.nazir@gmail.com)
 *
 */
public class ConnectionValidator {
	
	static Logger logger = Logger.getLogger(ConnectionValidator.class);

	
	public static boolean isInternetReachable(String urlCheck){
		
		try {
			
			URL url = new URL(urlCheck);
			HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection();
			urlConnect.getContent();
			
		} catch (UnknownHostException e) {
			logger.error("IP address of a host could not be determined " + urlCheck + " " + e.getMessage());
			return false;
		}catch (IOException e) {
			logger.error("Error connecting " + urlCheck + " " + e.getMessage());
			return false;
		}
		logger.info("Connection successful to " + urlCheck);
		return true;

	}
}
